package info.androidhive.tabsswipe;


import java.util.ArrayList;
import java.util.HashMap;

import com.example.newscrolling.service.UserDAO;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MovieBaseAdapter extends BaseAdapter {

	private LayoutInflater layoutInflater;
	private ArrayList<HashMap> arrayList;
	private static final String TAG = "MovieBaseAdapter";

	public MovieBaseAdapter (Context context, ArrayList<HashMap> arrayList){
		layoutInflater = LayoutInflater.from(context);
		this.arrayList = arrayList;
		
	}
	

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arrayList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		TagView tag;
		Bitmap bit;
		UserDAO userDao = new UserDAO();
		
		if(convertView == null) {
			convertView = layoutInflater.inflate(R.layout.activity_base_adapter,null);
			
			tag = new TagView();
			tag.setName((TextView) convertView.findViewById(R.id.AdapterTextName));
			tag.setTime((TextView)convertView.findViewById(R.id.AdapterTextDate));
			tag.setImage((ImageView)convertView.findViewById(R.id.AdapterImage));
		}else{
			tag = (TagView) convertView.getTag();
		}
		Log.i(TAG,"1");
		byte[] dataImage = (byte[]) (arrayList.get(position).get("image"));
		Log.i(TAG,"11");
		tag.name.setText("片名: " + arrayList.get(position).get("name"));
		Log.i(TAG,"12");
		tag.time.setText("上映日期: " + arrayList.get(position).get("time"));
		Log.i(TAG,"13");
		tag.image.setImageBitmap(userDao.getBmp(dataImage));
		Log.i(TAG,"14");
		return convertView;
		

	}
}
